\start83\
\comment=Ti-GO version 1.4
\comment=By Ben Axelrod
\comment=Jan. 17 2004
\name=TIGO
\file=C:\GRAPHL~1\GO\TIGO.TXT
ClrHome
AxesOff
PlotsOff 
FnOff 

\comment= set window
1\->\Xmin
95\->\Xmax
1\->\Xscl
\(-)\5\->\Ymin
57\->\Ymax
1\->\Yscl
1\->\Xres

\comment= initialize board
\comment= matrix is 11x11 to accomodate sides
\comment= 0 = no stone
\comment= 1 = black stone
\comment= 2 = white stone
\comment= 3 = board edge
{11,11}\->\dim([G]
0[G]\->\[G]
For(X,1,11)
3\->\[G](1,X)
3\->\[G](11,X)
3\->\[G](X,1)
3\->\[G](X,11)
End

\comment= variable H is for handicap stones
0\->\H

\comment= main menu
Menu("T\i\-GO","START GAME",ST,"HANDICAP",HN,"LOAD BOARD",LD,"EXIT",EX)

\comment= handicap stone label
Lbl HN
1\->\H
Lbl ST

\comment= variable T is whose turn it is:
\comment= 1 = black's turn
\comment= 2 = white's turn
\comment= variable O is number of stones black captured
\comment= variable P is number of stones white captured
1\->\T
0\->\O
0\->\P
ClrDraw
RecallPic 3

\comment= label 3 is for a loaded game
Lbl 3

\comment= X and Y are the coordinates of the current cursor position
\comment= A and B are the coordinates of the last cursor position
\comment= they are relative to an origin i defined off of the
\comment= lower left corner of the board.  every 6 pixels = 1 position
"ABCDEFGHJ"\->\Str3
30\->\X
30\->\Y
30\->\A
30\->\B

6\->\R
6\->\S

\comment= label 1 is where you return to when you need to re-draw the cursor
Lbl 1

\comment= displays the cursor's position
Text(1,86,sub(Str3,X/6,1)
Text(1,90,Y/6

\comment= delete the old cursor
Line(A-3,B+3,A+3,B+3,0
Line(A+3,B+2,A+3,B-2,0
Line(A+3,B-3,A-3,B-3,0
Line(A-3,B-2,A-3,B+2,0
If A>6
Pt-On(A-3,B
If A<54
Pt-On(A+3,B
If B>6
Pt-On(A,B-3
If B<54
Pt-On(A,B+3

\comment= draw new cursor
Line(X-3,Y+3,X+3,Y+3
Line(X+3,Y+2,X+3,Y-2
Line(X+3,Y-3,X-3,Y-3
Line(X-3,Y-2,X-3,Y+2

\comment= label 2 is where you return to after placing a stone
Lbl 2

While 1
getKey\->\K
\comment= drop stone
\comment= [Enter] = 105
\comment= [Graph] = 15
If K=15 or K=105
Then
\comment= if location is empty
If [G](11-Y/6,X/6+1)=0
Then
\comment= location of placed stone

Y\->\R
X\->\S
Text(31,83,sub(Str3,S/6,1)
Text(31,87,R/6

If T=2
Then
\comment= draw white stone
Line(X-2,Y-1,X-2,Y+1
Line(X-1,Y+2,X+1,Y+2
Line(X+2,Y+1,X+2,Y-1
Line(X+1,Y-2,X-1,Y-2
Line(X-1,Y,X+1,Y,0
Line(X,Y+1,X,Y-1,0
\comment= toggle turn
1\->\T
\comment= put stone into matrix
2\->\[G](11-R/6,S/6+1)
Text(1,61,"BLACK
Else
\comment= draw black stone
Line(X-2,Y+1,X-2,Y-1
Line(X-1,Y+2,X-1,Y-2
Line(X+1,Y+2,X+1,Y-2
Line(X+2,Y+1,X+2,Y-1
Line(X,Y+2,X,Y-2
\comment= put stone into matrix
1\->\[G](11-R/6,S/6+1)
\comment= change color only if not in handicap mode
If H=0
Then
2\->\T
Text(1,61,"WHITE
End
End
End
End

\comment= kill dead stones
\comment= [Trace] = 14
If K=14
Then
Text(1,61,"  WAIT "
\comment= start DSA
0\->\D
\(-)\1\->\E
\comment= iterate around the placed stone
For(F,1,4)
{1,2}\->\dim([H])
\comment= if stone is of target color
If ([G](11-R/6+D,S/6+1+E)=T)
Then
\comment= add stone to top of list
11-R/6+D\->\[H](1,1)
S/6+1+E\->\[H](1,2)
1\->\L
1\->\G
\comment= iterate through the stones in the list
While G\<=\L
0\->\M
\(-)\1\->\N
1\->\Z
\comment= iterate around each stone
While Z\<=\4
\comment= if neighbor is also of target color
If ([G]([H](G,1)+M,[H](G,2)+N)=T)
Then
1\->\J
1\->\I
\comment= iterate through list to check if the
\comment= stone is already on there
While I\<=\L
\comment= if stone is on list
If (([H](G,1)+M=[H](I,1)) and ([H](G,2)+N)=[H](I,2))
Then
\comment= break loop and set J
L+2\->\I
0\->\J
End
I+1\->\I
End
\comment= if stone was not on list already
If (J=1)
Then
\comment= add stone to bottom of list
L+1\->\L
{L,2}\->\dim([H])
[H](G,1)+M\->\[H](L,1)
[H](G,2)+N\->\[H](L,2)
End
End
\comment= if neighbor is empty
If ([G]([H](G,1)+M,[H](G,2)+N)=0)
Then
\comment= group has liberty
\comment= break all the way out to F loop
0\->\L
5\->\Z
End
M\->\J
N\->\M
\(-)\1*J\->\N
Z+1\->\Z
End
1+G\->\G
End
\comment= if there are stones in the list to erase
If (L>0)
Then
\comment= iterate through list
For(J,1,L)
\comment= erase stone
6*([H](J,2)-1)\->\M
6*(11-[H](J,1))\->\N
Line(M-2,N+1,M-2,N-1,0
Line(M-1,N+2,M-1,N-2,0
Line(M+1,N+2,M+1,N-2,0
Line(M+2,N+1,M+2,N-1,0
Line(M-2,N,M+2,N
Line(M,N+1,M,N-1
If M=54:Line(M+1,N,M+2,N,0
If M=6:Line(M-1,N,M-2,N,0
If N=54:Line(M,N+1,M,N+2,0
If N=6:Line(M,N-1,M,N-2,0
0\->\[G]([H](J,1),[H](J,2))
End
End
\comment= update prisoner counters
If T=2:O+L\->\O
If T=1:P+L\->\P
End
D\->\J
E\->\D
\(-)\1*J\->\E
End
\comment= end DSA
If T=1
Then
Text(1,61,"BLACK
Text(47,87,P
Else
Text(1,61,"WHITE
Text(47,68,O
End
End

\comment= pass
\comment= [Zoom] = 13
If K=13
Then
0\->\H
If T=1
Then
Text(1,61,"WHITE
2\->\T
Else
Text(1,61,"BLACK
1\->\T
End
End



\comment= save
\comment= [Window] = 12
If K=12:Goto SV

\comment= Exit
\comment= [Y=] = 11
If K=11:Goto EX

\comment= Move cursor left
\comment= [<-] = 24
If K=24
Then
X\->\A
Y\->\B
X-6\->\X
If X=0:54\->\X
Goto 1
End

\comment= Move cursor up
\comment= [^] = 25
If K=25
Then
X\->\A
Y\->\B
Y+6\->\Y
If Y=60:6\->\Y
Goto 1
End

\comment= Move cursor right
\comment= [^] = 26
If K=26
Then
X\->\A
Y\->\B
X+6\->\X
If X=60:6\->\X
Goto 1
End

\comment= Move cursor down
\comment= [v] = 34
If K=34
Then
X\->\A
Y\->\B
Y-6\->\Y
If Y=0:54\->\Y
Goto 1
End

\comment= move cursor to upper left hoshi
\comment= [7] = 72
If K=72
Then
X\->\A
Y\->\B
42\->\Y
18\->\X
Goto 1
End

\comment= move cursor to upper middle hoshi
\comment= [8] = 73
If K=73
Then
X\->\A
Y\->\B
42\->\Y
30\->\X
Goto 1
End

\comment= move cursor to upper right hoshi
\comment= [9] = 74
If K=74
Then
X\->\A
Y\->\B
42\->\Y
42\->\X
Goto 1
End

\comment= move cursor to middle left hoshi
\comment= [4] = 82
If K=82
Then
X\->\A
Y\->\B
30\->\Y
18\->\X
Goto 1
End

\comment= move cursor to tengen
\comment= [5] = 83
If K=83
Then
X\->\A
Y\->\B
30\->\Y
30\->\X
Goto 1
End

\comment= move cursor to middle right hoshi
\comment= [6] = 84
If K=84
Then
X\->\A
Y\->\B
30\->\Y
42\->\X
Goto 1
End

\comment= move cursor to lower left hoshi
\comment= [1] = 92
If K=92
Then
X\->\A
Y\->\B
18\->\Y
18\->\X
Goto 1
End

\comment= move cursor to lower middle hoshi
\comment= [2] = 93
If K=93
Then
X\->\A
Y\->\B
18\->\Y
30\->\X
Goto 1
End

\comment= move cursor to lower right hoshi
\comment= [1] = 94
If K=94
Then
X\->\A
Y\->\B
18\->\Y
42\->\X
Goto 1
End

End

\comment= exit game
Lbl EX
ZStandard
ClrHome
DelVar [G]
DelVar [H]
DelVar Str3
AxesOn
Stop

\comment= save game
Lbl SV
ClrHome
Output(4,4,"SAVING...
For(M,2,10)
0\->\Z
4^8\->\D
For(N,2,10)
D*[G](M,N)+Z\->\Z
D/4\->\D
End
Z\->\\L\GO(M-1)
End
T\->\\L\GO(10)
O\->\\L\GO(11)
P\->\\L\GO(12)
ClrHome
Menu("RETURN TO GAME?","YES",1,"NO",EX)

\comment= load game label
Lbl LD
ClrDraw
RecallPic 3
Text(1,61,"LOADN
For(M,2,10)
4^8\->\Z
\L\GO(M-1)\->\J
For(N,2,10)
iPart(J/Z)\->\[G](M,N)
J-Z*[G](M,N)\->\J
Z/4\->\Z

6*(N-1)\->\D
6*(11-M)\->\E

\comment= draw white stone
If [G](M,N)=2
Then
Line(D-2,E-1,D-2,E+1
Line(D-1,E+2,D+1,E+2
Line(D+2,E+1,D+2,E-1
Line(D+1,E-2,D-1,E-2
Line(D-1,E,D+1,E,0
Line(D,E+1,D,E-1,0
End

\comment= draw black stone
If [G](M,N)=1
Then
Line(D-2,E+1,D-2,E-1
Line(D-1,E+2,D-1,E-2
Line(D+1,E+2,D+1,E-2
Line(D+2,E+1,D+2,E-1
Line(D,E+2,D,E-2
End

End
End
\L\GO(10)\->\T
\L\GO(11)\->\O
\L\GO(12)\->\P
Text(47,87,P
Text(47,68,O

If T=1:Text(1,61,"BLACK
If T=2:Text(1,61,"WHITE

Goto 3
\comment=Play Go on your calculator!
\stop83\

